﻿Public Class FormFragment
    Public oColFragments As New ClassColFragments

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'Save
        If oColFragments.Contains(Me.ComboBox1.Text) Then
            Dim oFragment As ClassFragment = oColFragments.Item(Me.ComboBox1.Text)
            oFragment.Contenu = Me.TextBox1.Text
        Else
            Dim oFragment As New ClassFragment
            oFragment.Titre = Me.ComboBox1.Text
            oFragment.Contenu = Me.TextBox1.Text
            oColFragments.add(oFragment.Titre, oFragment)
            Me.ComboBox1.Items.Add(Me.ComboBox1.Text)
        End If
    End Sub

    Private Sub ButtonDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDel.Click
        'Delete
        If oColFragments.Contains(Me.ComboBox1.Text) Then oColFragments.Remove(Me.ComboBox1.Text)
        If Me.ComboBox1.Items.Contains(Me.ComboBox1.Text) Then Me.ComboBox1.Items.Remove(Me.ComboBox1.Text)
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        'Select
        If Me.ComboBox1.Text <> "" Then
            If oColFragments.Contains(Me.ComboBox1.Text) Then
                Dim ofragment As ClassFragment = oColFragments.Item(Me.ComboBox1.Text)
                Me.TextBox1.Text = ofragment.Contenu
            End If
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Me.TextBox1.Text &= Replace(Replace(Form1.RichTextBox1.SelectedText, vbCrLf, vbLf), vbLf, vbCrLf)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Save
        If oColFragments.Contains(Me.ComboBox1.Text) Then
            Dim oFragment As ClassFragment = oColFragments.Item(Me.ComboBox1.Text)
            oFragment.Contenu = Me.TextBox1.Text
        Else
            Dim oFragment As New ClassFragment
            oFragment.Titre = Me.ComboBox1.Text
            oFragment.Contenu = Me.TextBox1.Text
            oColFragments.add(oFragment.Titre, oFragment)
            Me.ComboBox1.Items.Add(Me.ComboBox1.Text)
        End If
        Me.DialogResult = Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub
End Class